package com.quocnv.mediascanner;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;

import org.apache.http.conn.util.InetAddressUtils;

import jcifs.Config;
import jcifs.UniAddress;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends ActionBarActivity implements OnClickListener
{
	private static final String TAG = "MainActivity";
	Button btnShowAll;
	Button btnShowTree;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		btnShowAll = (Button) findViewById(R.id.btnShowAll);
		btnShowTree = (Button) findViewById(R.id.btnShowTree);

		btnShowAll.setOnClickListener(this);
		btnShowTree.setOnClickListener(this);

		Thread thr = new Thread(new Runnable()
		{

			@Override
			public void run()
			{
				test();
				// checkListIp();
			}
		});
		thr.start();

	}

	private void test()
	{
		jcifs.Config.registerSmbURLHandler();
		SmbFile file;
		try
		{
			NtlmPasswordAuthentication authen = new NtlmPasswordAuthentication(
					null, null, null);
			file = new SmbFile("smb://", authen);
			// SmbFileOutputStream smbfos = new SmbFileOutputStream(file);

			String[] strs = file.list();

			for (String str : strs)
			{
				Log.e("quocnv", str);
			}
			Log.e("quocnv", "OK");
		} catch (MalformedURLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SmbException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void onClick(View v)
	{
		Intent i = new Intent(this, ShowFileActivity.class);

		switch (v.getId())
		{
		case R.id.btnShowAll:
			i.putExtra("show_type", 1);
			startActivity(i);
			break;
		case R.id.btnShowTree:
			i.putExtra("show_type", 0);
			startActivity(i);
			break;

		default:
			break;
		}
	}

}
